import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—15
 * Time: 8:50
 */
class Fruit implements Comparable<Fruit>{
    public int age;
    //必须告诉priorityQueue.offer 以什么方式比较添加元素
    @Override
    public int compareTo(Fruit o) {
        return this.age - o.age;
    }
}

public class Demo01 {

    public static int[] topK2(int[] array, int k) {
        int[] ret = new int[k];
        if(k == 0) return ret;
        PriorityQueue<Integer> maxPQ = new PriorityQueue<>(k,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for (int i = 0; i < array.length; i++) {
            if (maxPQ.size() < k) {
                maxPQ.offer(array[i]);
            }else {
                //获取到堆顶的元素
                int top = maxPQ.peek();
                //找前k个最小的元素
                if (array[i] < top) {
                    maxPQ.poll();
                    maxPQ.offer(array[i]);
                }
            }
        }
        for (int i = 0; i < k; i++) {
            ret[i] = maxPQ.poll();
        }
        return ret;
    }

    public static void topK1(int[] array, int k) {
        PriorityQueue<Integer> maxPQ = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for (int i = 0; i < array.length; i++) {
            maxPQ.offer(array[i]);
        }
        for (int i = 0; i < k; i++) {
            int val = maxPQ.poll();
            System.out.println(val);
        }
        System.out.println();
    }
    public static void main4(String[] args) {
        int[] array = {16,15,22,155,89,12,45};
        topK1(array,3);
    }
    public static void main3(String[] args) {
        PriorityQueue<Fruit> priorityQueue = new PriorityQueue<>();
//        priorityQueue.offer(new Fruit() );
//        priorityQueue.offer(new Fruit() );
        priorityQueue.offer(null );
        //priorityQueue.offer(null);
    }
    public static void main2(String[] args) {
        //默认是小根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(45);
        priorityQueue.offer(12);
        priorityQueue.offer(55);
        priorityQueue.offer(66);
        System.out.println(priorityQueue.peek());
       System.out.println(priorityQueue.poll());
    }
    public static void main1(String[] args) {
        MyHeap myHeap = new MyHeap();
        int[] array = {32,16,19,20,28,34,66,48,25,38};
        myHeap.initArray(array);
        myHeap.createHeap();
        myHeap.heapSort();
//        myHeap.offer(80);
//        myHeap.poll();
        System.out.println("asdasd");
    }

    public static void main(String[] args) {
//        int a = 10;
//        long b = 20;
//
//        int c = a + b;//编译失败 a+b->int+long->long+long 赋值给int会丢失数据
//        long d = a + b;//编译通过 赋值给long就可以

//        byte a = 10;
//        byte b = 20;
//        int  c1 = a + b;
//        System.out.println(c1);//编译失败，从a+b-》提升为 int+int-》byte 可能会有损失
//
//        byte c2 = (byte)(a + b);
//        System.out.println(c2);;//编译通过，将int强制转化为byte
//        int e = 10;
//        String num = e+ " ";
//        String num2 = String.valueOf(10);
//        String num3 = (String) num;
//        String str = "123";
//        int num4 = Integer.parseInt(str);
//
//            System.out.println("msg");
//            System.out.print("msg");
//            int x = 10;
//            System.out.printf("x=%d",x);

        Scanner scanner = new Scanner(System.in);
        String arr = scanner.next();
        System.out.println(arr);
        }

}



